#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Unit Test for spider.Spider
"""

import unittest
import spider

class SpiderTest(unittest.TestCase):
    """Spider UnitTest Case"""
    
    start_url = 'http://item.taobao.com/auction/item_detail.jhtml?x_id=0db2&item_id=568d84f05723c7a8b81c54071f3d0220'
    templates = [
        {
        'info': ur"""
            (?P<category>[\s\S]*?)
        
            (?:[\s\S]*?
            <div[^<>]*?class="detail-hd"[^<>]*?>
            (?P<name>[\s\S]*?)
            </div>)?
            price
            ShippingCost
            StartTime
            EndTime
            IfHaveInvoice 发票
            IfMaintenance 保修
            lastModified
            (?P<attributes>[\s\S]*?)
            
            seller-info
            """,
        }
    ]
    
    def setUp(self):
        "Hook method for setting up the test fixture before exercising it."
        self.spider = spider.Spider(self.start_url, self.templates)
    def test_spider(self):
        for level, url, parenturl, response, \
                    content, downurls, info in self.spider.walk():
            print '-' * 60
            if info:
                print level, url, parenturl, len(downurls)
                print info
                for k, v in info.iteritems():
                    print k, ':', v
            else:
                print level, url, parenturl, downurls

if __name__ == '__main__':
    unittest.main()